import http from '../../services/http';

const state = {
	orderPut:[],
	orderWait:[],
	orderProcess:[],
	orderComplete:[],
};

const mutations = {
  setOrderPut (state, payload) {
  	const {data} = payload;
  	state.orderPut = data;
  },
  setOrderWait (state, payload) {
  	const {data} = payload;
  	state.orderWait = data;
  },
  setOrderProcess (state, payload) {
  	const {data} = payload;
  	state.orderProcess = data;
  },
  setOrderComplete (state, payload) {
  	const {data} = payload;
  	state.orderComplete = data;
  },
  
};

const actions = {
	
	getOrderPut({ commit }, payload) {
		return new Promise((resolve, reject) => {
			http.get("/isp/api/v1/protected/order/list",{
				status: "SUBMITED"
			},(redata) => {
				if(redata.success) {
					commit({
						type: 'setOrderPut',
						data: redata.data
					});
					resolve(redata);
				} else {
					reject('getOrderPut--失败')
				}
			})
		})
	},
	getOrderWait({ commit }, payload) {
		return new Promise((resolve, reject) => {
			http.get("/isp/api/v1/protected/order/list",{
				status: "EXPECT_SERVE"
			} ,(redata) => {
				if(redata.success) {
					commit({
						type: 'setOrderWait',
						data: redata.data
					});
					resolve(redata);
				} else {
					reject('getOrderWait--失败')
				}
			})
		})
	},
	getOrderProcess({ commit }, payload) {
		return new Promise((resolve, reject) => {
			http.get("/isp/api/v1/protected/order/list",{
				status: "SERVING"
			} ,(redata) => {
				if(redata.success) {
					commit({
						type: 'setOrderProcess',
						data: redata.data
					});
					resolve(redata);
				} else {
					reject('getOrderProcess--失败')
				}
			})
		})
	},
	getOrderComplete({ commit }, payload) {
		return new Promise((resolve, reject) => {
			http.get("/isp/api/v1/protected/order/list",{
				status: "COMPLETED"
			} ,(redata) => {
				if(redata.success) {
					commit({
						type: 'setOrderComplete',
						data: redata.data
					});
					resolve(redata);
				} else {
					reject('getOrderComplete--失败')
				}
			})
		})
	},
};

export default {
  state,
  mutations,
  actions
};
